<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c"
           uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="auth" uri="http://www.recharge.com/authority" %>
<auth:authority role="0" />
<%--
这边要注意一个easyui 的问题，当panel tabs 这种href 引用页面
页面中不能有html body head 因为他只会把body 里面的内容 append 到页面中
--%>
<!-- <div style="width:auto; border:1px solid #F00"> -->
<div id="tradeOrder-dataCondition" class="easyui-panel"
     style="width:auto; height:150px;padding:10px;background:#fafafa;"
     data-options="closable:false,
                collapsible:false,minimizable:false,maximizable:false">
    <form id="tradeOrder-MainForm" method="post">

        <table>
            <tr>
                <td><label for="orderId">订单号:</label></td>
                <td><input class="easyui-validatebox" type="text" name="orderId" id="orderId"/></td>
                <td><label for="merId">商户号:</label></td>
                <td><input class="easyui-validatebox" type="text" name="merId" id="merId" value="<c:if test="${sessionScope.LOGIN_KEY.role==0}"><c:out value="${sessionScope.LOGIN_KEY.merId}"></c:out></c:if>" <c:if test="${sessionScope.LOGIN_KEY.role==0}"> readonly="true"</c:if>/></td>
                <td><label for="startTime">起始时间:</label></td>
                <td><input class="easyui-datetimebox" data-options="formatter:myformatter,sharedCalendar:'#cc'" id="startTime" name="startTime"></td>
                <td><label for="endTime">结束时间:</label></td>
                <td><input class="easyui-datetimebox" data-options="formatter:myformatter,sharedCalendar:'#cc'" id="endTime" name="endTime"></td>
            </tr>

            <tr>
                <td><label for="product">商品:</label></td>
                <td><input class="easyui-validatebox" type="text" name="product" id="product"/></td>
                <td><label for="chargeNumber">充值号码:</label></td>
                <td><input class="easyui-validatebox" type="text" name="chargeNumber" id="chargeNumber"/></td>
                <td><label for="chargeMoney">充值流量值:</label></td>
                <td><input class="easyui-validatebox" type="text" name="chargeMoney" id="chargeMoney"/></td>
                <td><label for="orderStatus">订单状态:</label></td>
                <td><select id="orderStatus" name="orderStatus">
                    <option selected></option>
                    <option value="0">成功</option>
                    <option value="1">待处理</option>
                    <option value="2">处理中</option>
                    <option value="3">失败</option>
                    <option value="4">假成功</option>
                    <option value="6">手工成功</option>
                    <option value="7">手工处理</option>
                    <option value="9">结果未知</option>
                </select></td>
            </tr>

            <tr>
                <td><label for="merOrderid">商户订单号:</label></td>
                <td><input class="easyui-validatebox" type="text" name="merOrderid" id="merOrderid"/></td>
                <td><label for="faceValue">面值:</label></td>
                <td><input class="easyui-validatebox" type="text" name="faceValue" id="faceValue"/></td>
                <td><label for="tmStatus">回调商户状态:</label></td>
                <td><select id="tmStatus" name="tmStatus">
                    <option selected></option>
                    <option value="0">成功</option>
                    <option value="3">失败</option>
                </select></td>
                <td><label for="supId">供货商id:</label></td>
                <td><input class="easyui-validatebox" type="text" name="supId" id="supId"/></td>
            </tr>

            <tr>
                <td colspan="3"></td>
                <td><input type="button" id="submit_tradeOrderMainForm" value="查询" onclick="submitTradeOrderMainForm();">
                </td>
            </tr>
        </table>
    </form>
</div>


<div id="dataView" class="easyui-panel" title="查询结果"
     style="width:auto;background:#fafafa; height:415px;overflow-y:hidden;"
     data-options="closable:false,
                collapsible:false,minimizable:false,maximizable:true">
    <table id="tradeOrder-dg">
    </table>
</div>

<script language="JavaScript" type="text/javascript">

    function myformatter(date){
        var y = date.getFullYear();
        var m = date.getMonth()+1;
        var d = date.getDate();
        var hh24 = date.getHours();
        var mi = date.getMinutes();
        var sec = date.getSeconds();
        return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d)+' '+(hh24<10?('0'+hh24):hh24)+":"+(mi<10?('0'+mi):mi)+":"+(sec<10?('0'+sec):sec);
    }

    $().ready(function () {

        //初始化查询结果表格
        $('#tradeOrder-dg').datagrid({
            columns:[[
                {field:'orderId',title:'猫拍订单号',width:100},
                {field:'merId',title:'商户号',width:100},
                {field:'product',title:'商品',width:150},
                {field:'chargeNumber',title:'充值号码',width:100},
                {field:'chargeMoney',title:'充值金额',width:100},
                {field:'orderStatus',title:'订单状态',width:100,formatter: function(value,row,index){
                    if(value == "0"){
                        return "成功";
                    }else if(value == "1"){
                        return "待处理";
                    }else if(value == "2"){
                        return "处理中";
                    }else if(value == "3"){
                        return "失败";
                    }else if(value == "4"){
                        return "假成功";
                    }else if(value == "6"){
                        return "手工成功";
                    }else if(value == "7"){
                        return "手工处理";
                    }else if(value == "9"){
                        return "结果未知";
                    }else{
                        return "不识别的状态";
                    }
                }},
                {field:'errCode',title:'错误码',width:100},
                {field:'orderTime',title:'订单时间',width:130},
                {field:'finishTime',title:'完成时间',width:130},
                {field:'merOrderid',title:'商户订单号',width:100},
                {field:'notifyUrl',title:'通知URL',width:100},
                {field:'faceValue',title:'面值',width:70},
                {field:'payMoney',title:'销售价',width:70},
                <auth:authority role="1">
                {field:'orderCost',title:'成本',width:70},
                    </auth:authority>
                {field:'tmStatus',title:'商户回调状态',width:100,formatter: function(value,row,index){
                    if(value == "0"){
                        return "成功";
                    }else if(value == "3"){
                        return "失败";
                    }else{
                        return "未知回调状态";
                    }
                }},
                {field:'processStrtus',title:'订单处理情况',width:200}
                <auth:authority role="1">,
                {field:'supId',title:'当前供货商编号',width:100},
                {field:'supList',title:'供货商列表',width:100},
                    </auth:authority>
            ]],
            pagination: true,
            height: 390<auth:authority role="1">,
            toolbar: [{
                iconCls: 'icon-add',
                text : "继续充值",
                handler: function(){
                    $.messager.confirm('Confirm','确认从新提交?',function(r){
                        if (r){
                            var selectOrder = $('#tradeOrder-dg').datagrid("getSelected");
                            if(selectOrder==null){
                                $.messager.alert('Warn','未选中要操作的订单');
                                return;
                            }
                            var orderId =selectOrder.orderId;
                            operTradeOrder(orderId,"continue_recharge");
                            $.messager.alert('Info','操作成功');
                        }
                    });

                }
            },{
                iconCls: 'icon-add',
                text : "成功,且回调成功",
                handler: function(){
                    $.messager.confirm('Confirm','成功,且回调成功?',function(r){
                        if (r){
                    var selectOrder = $('#tradeOrder-dg').datagrid("getSelected");
                    if(selectOrder==null){
                        $.messager.alert('Warn','未选中要操作的订单');
                        return;
                    }
                    var orderId =selectOrder.orderId;
                    operTradeOrder(orderId,"succ_callback_succ");
                    $.messager.alert('Info','操作成功');
                        }
                    });

                }
            },{
                iconCls: 'icon-add',
                text : "失败，但回调成功",
                handler: function(){
                    $.messager.confirm('Confirm','失败，但回调成功?',function(r){
                        if (r){
                    var selectOrder = $('#tradeOrder-dg').datagrid("getSelected");
                    if(selectOrder==null){
                        $.messager.alert('Warn','未选中要操作的订单');
                        return;
                    }
                    var orderId =selectOrder.orderId;
                    operTradeOrder(orderId,"fail_callback_succ");
                    $.messager.alert('Info','操作成功');
                        }
                    });
                }
            },{
                iconCls: 'icon-add',
                text : "失败，回调失败",
                handler: function(){
                    $.messager.confirm('Confirm','失败，回调失败?',function(r){
                        if (r){
                    var selectOrder = $('#tradeOrder-dg').datagrid("getSelected");
                    if(selectOrder==null){
                        $.messager.alert('Warn','未选中要操作的订单');
                        return;
                    }
                    var orderId =selectOrder.orderId;
                    operTradeOrder(orderId,"fail_callback_fail");
                    $.messager.alert('Info','操作成功');
                        }
                    });
                }
            },{
                iconCls: 'icon-add',
                text : "不处理，只回调成功",
                handler: function(){
                    $.messager.confirm('Confirm','不处理，只回调成功?',function(r){
                        if (r){
                    var selectOrder = $('#tradeOrder-dg').datagrid("getSelected");
                    if(selectOrder==null){
                        $.messager.alert('Warn','未选中要操作的订单');
                        return;
                    }
                    var orderId =selectOrder.orderId;
                    operTradeOrder(orderId,"no_callback_succ");
                    $.messager.alert('Info','操作成功');
                        }
                    });
                }
            }]</auth:authority>
        });

        var pager = $('#tradeOrder-dg').datagrid().datagrid('getPager');
        pager.pagination({
            onBeforeRefresh:function(pageNumber, pageSize){
                tradeOrderGetListData(pageNumber,pageSize);
            },
            onSelectPage:function(pageNumber, pageSize){
                tradeOrderGetListData(pageNumber,pageSize);
            }
        });


    });

    function operTradeOrder(orderId,type){
        $.post("tradeOrder/operOrder", {"orderId":orderId,"type":type},function(responseInfo){
            $('#tradeOrder-dg').datagrid('loadData', {
                "total":responseInfo.count,
                "rows":responseInfo.data
            });
        });
    }

    function tradeOrderGetListData(pageNumber, pageSize){
        var param = $("#tradeOrder-MainForm").serializeArray();
        param.push({name:"curr",value:pageNumber});
        param.push({name:"pageSize",value:pageSize});

        $.post("tradeOrder/queryList", param,function(responseInfo){
            $('#tradeOrder-dg').datagrid('loadData', {
                "total":responseInfo.count,
                "rows":responseInfo.data
            });
        });

    }

    function submitTradeOrderMainForm() {
        var param = $("#tradeOrder-MainForm").serializeArray();
        param.push({name:"curr",value:1});
        param.push({name:"pageSize",value:10});

        $.post("tradeOrder/queryList", param,function(responseInfo){
            $('#tradeOrder-dg').datagrid('loadData', {
                "total":responseInfo.count,
                "rows":responseInfo.data
            });
        });
    }
</script>